home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Using a Brush to Fill Shapes / Tiling a Shape with an Image / GDITEST23.dpr
Encoding:
Text File  |  2003-10-15  |  3.0 KB  |  112 lines

  1. program GDITEST23;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10.  
  11. Procedure OnPaint(DC: HDC);
  12. var
  13.   graphics : TGPGraphics;
  14.   Image: TGPImage;
  15.   tBrush : TGPTextureBrush;
  16.   blackPen: TGPPen;
  17. begin
  18.   graphics := TGPGraphics.Create(DC);
  19.  
  20.   Image := TGPImage.Create('..\..\Media\Tile1.gif');
  21.   tBrush := TGPTextureBrush.Create(image);
  22.   blackPen := TGPPen.Create(MakeColor(255, 0, 0, 0));
  23.  
  24.   tBrush.SetWrapMode(WrapModeTile);
  25.   graphics.FillRectangle(tBrush, MakeRect(0, 0, 200, 200));
  26.   graphics.DrawRectangle(blackPen, MakeRect(0, 0, 200, 200));
  27.  
  28.   tBrush.SetWrapMode(WrapModeTileFlipX);
  29.   graphics.FillRectangle(tBrush, MakeRect(200, 0, 200, 200));
  30.   graphics.DrawRectangle(blackPen, MakeRect(200, 0, 200, 200));
  31.  
  32.   tBrush.SetWrapMode(WrapModeTileFlipY);
  33.   graphics.FillRectangle(tBrush, MakeRect(0, 200, 200, 200));
  34.   graphics.DrawRectangle(blackPen, MakeRect(0, 200, 200, 200));
  35.  
  36.   tBrush.SetWrapMode(WrapModeTileFlipXY);
  37.   graphics.FillRectangle(tBrush, MakeRect(200, 200, 200, 200));
  38.   graphics.DrawRectangle(blackPen, MakeRect(200, 200, 200, 200));
  39.  
  40.   Image.Free;
  41.   tBrush.Free;
  42.   blackPen.Free;
  43.   graphics.Free;
  44. end;
  45.  
  46.  
  47. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  48. var
  49.   Handle: HDC;
  50.   ps: PAINTSTRUCT;
  51. begin
  52.   case message of
  53.     WM_PAINT:
  54.       begin
  55.         Handle := BeginPaint(Wnd, ps);
  56.         OnPaint(Handle);
  57.         EndPaint(Wnd, ps);
  58.         result := 0;
  59.       end;
  60.  
  61.     WM_DESTROY:
  62.       begin
  63.         PostQuitMessage(0);
  64.         result := 0;
  65.       end;
  66.  
  67.    else
  68.       result := DefWindowProc(Wnd, message, wParam, lParam);
  69.    end;
  70. end;
  71.  
  72. var
  73.   hWnd     : THandle;
  74.   Msg      : TMsg;
  75.   wndClass : TWndClass;
  76. begin
  77.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  78.    wndClass.lpfnWndProc    := @WndProc;
  79.    wndClass.cbClsExtra     := 0;
  80.    wndClass.cbWndExtra     := 0;
  81.    wndClass.hInstance      := hInstance;
  82.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  83.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  84.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  85.    wndClass.lpszMenuName   := nil;
  86.    wndClass.lpszClassName  := 'GettingStarted';
  87.  
  88.    RegisterClass(wndClass);
  89.  
  90.    hWnd := CreateWindow(
  91.       'GettingStarted',       // window class name
  92.       'Tiling a Shape with an Image',       // window caption
  93.       WS_OVERLAPPEDWINDOW,    // window style
  94.       Integer(CW_USEDEFAULT), // initial x position
  95.       Integer(CW_USEDEFAULT), // initial y position
  96.       Integer(CW_USEDEFAULT), // initial x size
  97.       Integer(CW_USEDEFAULT), // initial y size
  98.       0,                      // parent window handle
  99.       0,                      // window menu handle
  100.       hInstance,              // program instance handle
  101.       nil);                   // creation parameters
  102.  
  103.    ShowWindow(hWnd, SW_SHOW);
  104.    UpdateWindow(hWnd);
  105.  
  106.    while(GetMessage(msg, 0, 0, 0)) do
  107.    begin
  108.       TranslateMessage(msg);
  109.       DispatchMessage(msg);
  110.    end;
  111. end.
  112.